<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head th:include="layout :: htmlhead"></head>
<head>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <style type="text/css">

        #demo2 > img {
            width: 33%;
            height: 115px;
        }
        #demo1 {
            width: 100%;
            height: 270px;
        }
        #div1 {
            position: relative;
        }
        #div5 {
            position: relative;
        }

        #div2 {
            width: 100px;
            height: 38px;
            background: #2178fc;
            color: #fff;
            text-align: center;
            line-height: 36px;
        }
        #div3 {
            width: 100px;
            height: 38px;
            background: #2178fc;
            color: #fff;
            text-align: center;
            line-height: 36px;
        }
        #div4 {
            width: 100px;
            height: 38px;
            background: #2178fc;
            color: #fff;
            text-align: center;
            line-height: 36px;
        }
        #div6 {
            width: 100px;
            height: 38px;
            background: #2178fc;
            color: #fff;
            text-align: center;
            line-height: 36px;
        }
        #div7 {
            width: 100px;
            height: 38px;
            background: #2178fc;
            color: #fff;
            text-align: center;
            line-height: 36px;
        }

        #file_input_one {
            width: 200px;/*因为file-input在部分浏览器中会自带一个输入框，需要双击才可以点击上传,放大后将其定位到div外面就好啦*/
            height: 36px;
            position: absolute;
            left: -100px;
            top: 0;
            z-index:1;
            -moz-opacity: 0;
            -ms-opacity: 0;
            -webkit-opacity: 0;
            opacity: 0; /*css属性——opcity不透明度，取值0-1*/
            filter: alpha(opacity=0); /*兼容IE8及以下--filter属性是IE特有的，它还有很多其它滤镜效果，而filter: alpha(opacity=0); 兼容IE8及以下的IE浏览器(如果你的电脑IE是8以下的版本，使用某些效果是可能会有一个允许ActiveX的提示,注意点一下就ok啦)*/
            cursor: pointer;
        }
        #file_input_more {
            width: 200px;/*因为file-input在部分浏览器中会自带一个输入框，需要双击才可以点击上传,放大后将其定位到div外面就好啦*/
            height: 36px;
            position: absolute;
            left: -100px;
            top: 0;
            z-index:1;
            -moz-opacity: 0;
            -ms-opacity: 0;
            -webkit-opacity: 0;
            opacity: 0; /*css属性——opcity不透明度，取值0-1*/
            filter: alpha(opacity=0); /*兼容IE8及以下--filter属性是IE特有的，它还有很多其它滤镜效果，而filter: alpha(opacity=0); 兼容IE8及以下的IE浏览器(如果你的电脑IE是8以下的版本，使用某些效果是可能会有一个允许ActiveX的提示,注意点一下就ok啦)*/
            cursor: pointer;
        }
        #dep_file_input_one {
            width: 200px;/*因为file-input在部分浏览器中会自带一个输入框，需要双击才可以点击上传,放大后将其定位到div外面就好啦*/
            height: 36px;
            position: absolute;
            left: -100px;
            top: 0;
            z-index:1;
            -moz-opacity: 0;
            -ms-opacity: 0;
            -webkit-opacity: 0;
            opacity: 0; /*css属性——opcity不透明度，取值0-1*/
            filter: alpha(opacity=0); /*兼容IE8及以下--filter属性是IE特有的，它还有很多其它滤镜效果，而filter: alpha(opacity=0); 兼容IE8及以下的IE浏览器(如果你的电脑IE是8以下的版本，使用某些效果是可能会有一个允许ActiveX的提示,注意点一下就ok啦)*/
            cursor: pointer;
        }
        #dep_file_input_more {
            width: 200px;/*因为file-input在部分浏览器中会自带一个输入框，需要双击才可以点击上传,放大后将其定位到div外面就好啦*/
            height: 36px;
            position: absolute;
            left: -100px;
            top: 0;
            z-index:1;
            -moz-opacity: 0;
            -ms-opacity: 0;
            -webkit-opacity: 0;
            opacity: 0; /*css属性——opcity不透明度，取值0-1*/
            filter: alpha(opacity=0); /*兼容IE8及以下--filter属性是IE特有的，它还有很多其它滤镜效果，而filter: alpha(opacity=0); 兼容IE8及以下的IE浏览器(如果你的电脑IE是8以下的版本，使用某些效果是可能会有一个允许ActiveX的提示,注意点一下就ok啦)*/
            cursor: pointer;
        }

    </style>
    <base th:href="@{/}">
    <!--<link rel="stylesheet" href="layui/css/layui.css">-->
</head>

<body class="layui-layout-body" style="overflow: auto;">
<!---->
<div class="layui-container">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>文件上传</legend>
    </fieldset>
</div>
<div style="padding: 20px; background-color: #F2F2F2;" class="layui-layout layui-layout-admin">
    <div class="layui-row layui-col-space5">
        <!--程序上传-->
        <div class="layui-col-md4">
                <div class="layui-card">
                    <div class="layui-card-header">程序上传</div>
                    <div class="layui-card-body">
                        <form class="layui-form" method="post">
                            <div class="layui-form-item">
                                <label class="layui-form-label">区域</label>
                                <div class="layui-input-inline">
                                    <select name="appArea" id="appArea" lay-filter="appArea" lay-verify="required">
                                        <option value=""></option>
                                        <option value="8">8寸</option>
                                        <option value="12">12寸</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">项目名称</label>
                                <div class="layui-input-inline">
                                    <select name="fileType" id="fileType" lay-filter="fileType" lay-verify="required">
                                        <option value=""></option>
                                        <option value="OPI">OPI</option>
                                        <option value="SPC">SPC</option>
                                        <option value="SM">SM</option>
                                        <option value="WISE">WISE</option>
                                        <option value="RPT">RPT</option>
                                        <option value="WISE_PKG">WISE_PKG</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">当前版本</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="prevVersion" autocomplete="off" readonly id="curVersion" lay-verify="curVersionNo" placeholder="" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">新版本号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="version" id="newVersion" autocomplete="off" lay-verify="newVersionNo" placeholder="请输入版本号" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <input type="hidden" id="file_url" name="path" value=""/>
                                <div class="layui-input-block">
                                    <div class="layui-upload">
                                        <button type="button" class="layui-btn layui-btn-normal" id="chooseFile"><i class="layui-icon">&#xe67c;</i>选择文件</button>
                                        <button type="button" class="layui-btn" lay-submit lay-filter="formSubmit">提交数据</button>
                                    </div>
                                </div>
                            </div>
                        </form>

                    </div>
                </div>
        </div>

        <!--SOP上传-->
        <div class="layui-col-md4">
            <div class="layui-card">
                <div class="layui-card-header">SOP上传</div>
                <div class="layui-card-body">
                    <div class="layui-form-item">
                        <label class="layui-form-label">SOP上传</label>
                        <form class="layui-form" action="./index/uploadSopFolder" id="uploadSopFolder" name="uploadSopFolder" method="post" enctype="multipart/form-data">
                            <a id="div1">
                                <div class="layui-input-block">
                                    <div class="layui-col-md5">
                                        <div class="layui-btn-group layui-upload" >
                                            <ul class="layui-nav layui-inline layui-bg-blue" style="font-size: 12px;border-radius: 2px;float: right;padding: 0px 5px 0px 0px;margin-left: 2px;">
                                                <li class="layui-nav-item" style="line-height: 20px; font-size: 12px;">
                                                    <a href="javascript:;" style="color:white;font-size: 12px;padding: 0px 20px 0px 20px;margin-top: 10px">上传</a>
                                                    <dl class="layui-nav-child" style="top: 30px;line-height: 20px;padding: 0px 0px 0px 0px;">
                                                        <dd>
                                                            <div class="layui-upload">
                                                                <div id="div3" class="layui-col-md5"><i class="layui-icon">&#xe67c;</i>选择文件
                                                                    <!--<input type="file" name="folder" id="file_input_one">-->
                                                                    <button type="button" class="layui-btn layui-btn-normal" id="file_input_one"></button>
                                                                </div>
                                                            </div>
                                                        </dd>
                                                        <dd>
                                                            <div id="div4" class="layui-col-md5"><i class="layui-icon">&#xe67c;</i>选择文件夹
                                                                <input type="file" name="sopFolder" id="file_input_more" webkitdirectory>
                                                            </div>
                                                        </dd>
                                                    </dl>
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                    <!--<div class="layui-col-md5">
                                        <button type="button" class="layui-btn" lay-submit lay-filter="sopFormSubmit">提交数据</button>
                                    </div>-->
                                </div>
                            </a>
                        </form>
                    </div>
                    <form class="layui-form" method="post">
                        <div class="layui-form-item">
                            <div class="layui-form-item">
                                <label class="layui-form-label">区域</label>
                                <div class="layui-input-inline">
                                    <select name="sopArea" id="sopArea" lay-filter="sopArea" lay-verify="required">
                                        <option value=""></option>
                                        <option value="8">8寸</option>
                                        <option value="12">12寸</option>
                                    </select>
                                </div>
                            </div>
                            <label class="layui-form-label">项目名称</label>
                            <div class="layui-input-inline">
                                <select name="sopFileType" id="sop_file_type" lay-filter="sopFileType" lay-verify="required">
                                    <option value=""></option>
                                    <option value="OPI">OPI</option>
                                    <option value="SPC">SPC</option>
                                    <option value="SM">SM</option>
                                    <option value="WISE">WISE</option>
                                    <option value="RPT">RPT</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">SOP版本号</label>
                            <div class="layui-input-inline">
                                <select name="sopVersion" id="sop_version" lay-filter="sopVersion" lay-verify="required">
                                    <option value=""></option>
                                </select>
                            </div>
                        </div>
                        <!--<div class="layui-form-item">
                            <label class="layui-form-label"></label>
                            <div class="layui-input-inline">
                                <input type="hidden" name="" autocomplete="off" readonly id="" lay-verify="" class="layui-input">
                            </div>
                        </div>-->
                        <div class="layui-form-item">
                            <input type="hidden" id="sop_file_url" name="sopPath" value=""/>
                            <div class="layui-input-block">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn" lay-submit lay-filter="sopFormSubmit">提交数据</button>
                                </div>
                            </div>
                        </div>
                    </form>

                </div>
            </div>

        </div>

        <!--依赖安装包上传-->
        <div class="layui-col-md4">
            <div class="layui-card">
                <div class="layui-card-header">依赖包上传</div>
                <div class="layui-card-body">
                    <div class="layui-form-item">
                        <label class="layui-form-label">依赖包上传</label>
                        <form class="layui-form" action="./index/uploadDepFolder" id="uploadDepFolder" name="uploadDepFolder" method="post" enctype="multipart/form-data">
                            <a id="div5">
                                <div class="layui-input-block">
                                    <div class="layui-col-md5">
                                        <div class="layui-btn-group layui-upload" >
                                            <ul class="layui-nav layui-inline layui-bg-blue" style="font-size: 12px;border-radius: 2px;float: right;padding: 0px 5px 0px 0px;margin-left: 2px;">
                                                <li class="layui-nav-item" style="line-height: 20px; font-size: 12px;">
                                                    <a href="javascript:;" style="color:white;font-size: 12px;padding: 0px 20px 0px 20px;margin-top: 10px">上传</a>
                                                    <dl class="layui-nav-child" style="top: 30px;line-height: 20px;padding: 0px 0px 0px 0px;">
                                                        <dd>
                                                            <div class="layui-upload">
                                                                <div id="div6" class="layui-col-md5"><i class="layui-icon">&#xe67c;</i>选择文件
                                                                    <!--<input type="file" name="folder" id="file_input_one">-->
                                                                    <button type="button" class="layui-btn layui-btn-normal" id="dep_file_input_one"></button>
                                                                </div>
                                                            </div>
                                                        </dd>
                                                        <dd>
                                                            <div id="div7" class="layui-col-md5"><i class="layui-icon">&#xe67c;</i>选择文件夹
                                                                <input type="file" name="depFolder" id="dep_file_input_more" webkitdirectory>
                                                            </div>
                                                        </dd>
                                                    </dl>
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </a>
                        </form>
                    </div>
                    <form class="layui-form" method="post">
                        <div class="layui-form-item">
                            <div class="layui-form-item">
                                <label class="layui-form-label">区域</label>
                                <div class="layui-input-inline">
                                    <select name="depArea" id="depArea" lay-filter="depArea" lay-verify="required">
                                        <option value=""></option>
                                        <option value="8">8寸</option>
                                        <option value="12">12寸</option>
                                    </select>
                                </div>
                            </div>
                            <label class="layui-form-label">项目名称</label>
                            <div class="layui-input-inline">
                                <select name="depFileType" id="dep_file_type" lay-filter="depFileType" lay-verify="required">
                                    <option value=""></option>
                                    <option value="OPI">OPI</option>
                                    <option value="SPC">SPC</option>
                                    <option value="SM">SM</option>
                                    <option value="WISE">WISE</option>
                                    <option value="RPT">RPT</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">&nbsp;</label>
                            <div class="layui-input-inline">
                                <input type="hidden" name="" autocomplete="off" readonly id="" lay-verify="" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <input type="hidden" id="dep_file_url" name="depPath" value=""/>
                            <div class="layui-input-block">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn" lay-submit lay-filter="depFormSubmit">提交数据</button>
                                </div>
                            </div>
                        </div>
                    </form>

                </div>
            </div>
        </div>

    </div>

    <div class="layui-row layui-col-space5">
        <div class="layui-col-md12">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">上传记录</div>
                    <div class="layui-card-body">
                        <textarea id="textArea" name="textArea" type="text/plain" style="width:99%;height: 203px"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--SOP文件上传-->
    <!--<div class="layui-row layui-col-space5">
        <div class="layui-col-md4">
            <div class="layui-card">
                <div class="layui-card-header">SOP上传</div>
                <div class="layui-card-body">
                    <form class="layui-form" method="post">
                        <div class="layui-form-item">
                            <label class="layui-form-label">项目名称</label>
                            <div class="layui-input-inline">
                                <select name="fileType" id="fileType" lay-filter="fileType" lay-verify="required">
                                    <option value=""></option>
                                    <option value="OPI">OPI</option>
                                    <option value="SPC">SPC</option>
                                    <option value="WISE">WISE</option>
                                    <option value="EDA">EDA</option>
                                    <option value="RPT">RPT</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">当前文件版本</label>
                            <div class="layui-input-inline">
                                <input type="text" name="prevVersion" autocomplete="off" readonly id="curVersion" lay-verify="required" placeholder="" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">新文件版本</label>
                            <div class="layui-input-inline">
                                <input type="text" name="version" id="newVersion" autocomplete="off" lay-verify="versionNo" placeholder="请输入版本号" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <input type="hidden" id="file_url" name="path" value=""/>
                            <div class="layui-input-block">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn layui-btn-normal" id="chooseFile"><i class="layui-icon">&#xe67c;</i>选择文件</button>
                                    <button type="button" class="layui-btn" lay-submit lay-filter="formSubmit">提交数据</button>
                                </div>
                            </div>
                        </div>
                    </form>

                </div>
            </div>
        </div>
        <div class="layui-col-md8">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">程序上传清单</div>
                    <div class="layui-card-body">
                        <textarea id="textArea" name="textArea" type="text/plain" style="width:99%;height: 203px"></textarea>
                    </div>
                </div>
            </div>
        </div>

    </div>-->

</div>
<!--
<script type="text/javascript" th:src="@{/layui/layui.js}"></script>
-->
<script type="text/javascript">
    /*文件&文件夹上传*/
    var file_input_more = document.getElementById('file_input_more');
    var dep_file_input_more = document.getElementById('dep_file_input_more');

    file_input_more.addEventListener('change', function() {
        var t_files = this.files;
        //console.log(t_files);
        var str = '';
        var totalSize = 0.0;
        for (var i = 0, len = t_files.length; i < len; i++) {
            //console.log(t_files[i]);
            str += "<"+(i+1)+">: "+t_files[i].name + '大小' + t_files[i].size / 1024 + 'KB \r\n';
            totalSize += t_files[i].size / 1024 / 1024;
        };
        var total = "共计："+t_files.length+"个文件,共计："+totalSize+"MB";

        $("#uploadSopFolder").ajaxSubmit(function(e) {
            console.log(e);
            console.log(e.path);
            if(e.status == 0){
                layer.msg("上传成功");
                // 清空url_value
                document.getElementById('sop_file_url').value = "";
                document.getElementById('sop_file_url').value = e.path;
            }else{
                layer.msg("上传成功");
            }
        });
        document.getElementById('textArea').innerHTML = total+"\r\n"+str;
    }, false);

    dep_file_input_more.addEventListener('change', function() {
        var t_files = this.files;
        //console.log(t_files);
        var str = '';
        var totalSize = 0.0;
        for (var i = 0, len = t_files.length; i < len; i++) {
            //console.log(t_files[i]);
            str += "<"+(i+1)+">: "+t_files[i].name + '大小' + t_files[i].size / 1024 + 'KB \r\n';
            totalSize += t_files[i].size / 1024 / 1024;
        };
        var total = "共计："+t_files.length+"个文件,共计："+totalSize+"MB";

        $("#uploadDepFolder").ajaxSubmit(function(e) {
            console.log(e);
            console.log(e.path);
            if(e.status == 0){
                layer.msg("上传成功");
                // 清空url_value
                document.getElementById('dep_file_url').value = "";
                document.getElementById('dep_file_url').value = e.path;
            }else{
                layer.msg("上传成功");
            }
        });
        document.getElementById('textArea').innerHTML = total+"\r\n"+str;
    }, false);

    /*
    file_input_one.addEventListener('change', function() {
        var t_files = this.files;
        console.log(t_files);
        var str = '';
        var totalSize = 0.0;
        for (var i = 0, len = t_files.length; i < len; i++) {
            console.log(t_files[i]);
            str += "<"+(i+1)+">: "+t_files[i].name + '大小' + t_files[i].size / 1024 + 'KB \r\n';
            totalSize += t_files[i].size / 1024 / 1024;
        };
        var total = "共计："+t_files.length+"个文件,共计："+totalSize+"MB";
        document.getElementById('textArea').innerHTML = total+"\r\n"+str;
    }, false);*/

    layui.use(['form', 'element', 'upload','jquery'], function() {
        var form = layui.form
            , layer = layui.layer
            , element = layui.element
            , $ = layui.jquery
            , upload = layui.upload;

        form.render('select');

        form.verify({
            newVersionNo: [/^[0-9]{1}\.[0-9]{1}\.[0-9]{1}\.[0-9]{1}$/, '版本格式不正确[1.0.0.1]！']
            ,curVersionNo: function(){
                var oldVersion = document.getElementById("curVersion").value;
                var newVersion = document.getElementById("newVersion").value;
                var oldVerNum = oldVersion.replace(/[^0-9]/ig,"");
                var newVerNum = newVersion.replace(/[^0-9]/ig,"");
                console.log(oldVerNum+"->"+newVerNum);
                if(oldVersion == newVersion){
                    return "不能和当前版本一致！";
                }
                if(oldVerNum >= newVerNum){
                    return "不能小于等于当前版本！";
                }
            }
        });

        //zip程序上传，选完文件后不自动上传
        form.on('select(fileType)', function(data) {
            var val = data.value;
            var area = document.getElementById("appArea").value;
            console.info(val);
            console.info(data);

            $.ajax({
                type: 'POST',
                url: "./index/getLastestVersion",
                //dataType: 'json',
                data: {fileType: data.value, appArea: area},//往后台发送的是data.field，即一个{name：value}的数据结构
                async: true,
                success: function (result) {
                    if (result.code == 0) {
                        layer.msg('成功获取版本！', {icon: 1, time: 1000});
                        document.getElementById("curVersion").value = result.version;
                        document.getElementById("textArea").value += "\r\n"+writeCurrentDate()+val+"当前版本："+result.version;
                    } else {
                        layer.msg('获取当前版本失败！' + result.msg, {icon: 2, time: 1000});
                        document.getElementById("textArea").value = "\r\n"+writeCurrentDate()+result.msg;
                    }
                },
                error: function (result, type) {
                    layer.msg('获取当前版本失败2！', {icon: 2, time: 1000});
                    document.getElementById("textArea").value = "\r\n"+writeCurrentDate()+result;
                }
            });
        });

        //程序上传信息提交
        form.on('submit(formSubmit)', function(data) {
            if(!data.field.path){
                layer.alert("请先选择上传的文件！！", {
                    icon: 1,
                    time: 3000,
                    title: '错误'
                });
                return false;
            }

            $.ajax({
                type: 'POST',
                url: "./index/upload_save",
                data: data.field,
                async: true,
                success: function(result) {
                    console.log(result);
                    if (result.code == 0) {
                        layer.msg('保存成功', {icon: 1, time: 3000});
                        document.getElementById("file_url").value = "";
                    } else {
                        layer.msg('保存失败！' + result.msg, {icon: 2, time: 3000});
                    }
                },
                error: function(result, type) {
                    layer.msg('保存失败！', {icon: 2, time: 3000});
                }
            });
        });


        upload.render({
            elem: '#chooseFile'
            ,url: './index/upload_one'
            ,auto: true
            ,multiple: true
            ,drag: true
            ,accept: 'file' //普通文件
            ,exts: 'zip' //只允许上传压缩文件
            ,bindAction: '#uploadBtn'
            ,progress: function(e , percent) {
                    console.log("进度：" + percent + '%');
                    element.progress('progressBar',percent  + '%');
            }
            ,before: function(obj) {
                layer.msg('文件上传中...', {
                    icon: 16,
                    shade: 0.01,
                    time: 0
                })
            }
            ,done: function(res){
                console.log(res);
                layer.close(layer.msg());
                if(res.code == "fail"){
                    layer.msg("上传失败！！！");
                }
                if(res.code == "success"){
                    layer.msg("上传完成");
                    // 调用上传表单
                    document.getElementById("file_url").value = res.url;
                    document.getElementById("textArea").value += "\r\n"+writeCurrentDate()+"Upload-->"+res.url;
                }
            }
        });
/*
        //sop文件选择
        upload.render({
            elem: '#sopChooseFile'
            ,url: './index/upload_sop'
            ,auto: true
            ,multiple: true
            ,drag: true
            ,accept: 'file' //普通文件
            //,exts: 'zip|rar|7z' //只允许上传压缩文件
            ,progress: function(e , percent) {
                console.log("进度：" + percent + '%');
                element.progress('progressBar',percent  + '%');
            }
            ,before: function(obj) {
                layer.msg('文件上传中...', {
                    icon: 16,
                    shade: 0.01,
                    time: 0
                })
            }
            ,done: function(res){
                console.log(res);
                layer.close(layer.msg());
                if(res.code == "fail"){
                    layer.msg("上传失败！！！");
                }
                if(res.code == "success"){
                    layer.msg("上传完成");
                    // 调用上传表单
                    document.getElementById("sop_file_url").value = "";
                    document.getElementById("sop_file_url").value = res.url;
                    document.getElementById("textArea").value += "\r\n"+writeCurrentDate()+"Sop Upload-->"+res.url;
                }
            }
        });*/

        //获取sop相关的版本信息，选完文件后不自动上传
        form.on('select(sopFileType)', function(data) {
            var val = data.value;
            var area = document.getElementById("sopArea").value;
            console.info(val);
            console.info(data);
            $.ajax({
                type: 'POST',
                url: "./index/getAllVersionByType",
                //dataType: 'json',
                data: {fileType: val, sopArea: area},//往后台发送的是data.field，即一个{name：value}的数据结构
                async: true,
                success: function (result) {
                    if (result.code == 0) {
                        $("#sop_version").empty();
                        $.each(result.version, function (i) {
                            $("#sop_version").append('<option value="' + result.version[i] + '">' + result.version[i] + '</option>');
                        })
                        form.render();//layui封装的遍历,每次绑定下拉框都需要加上
                        layer.msg('成功获取版本！', {icon: 1, time: 1000});
                        document.getElementById("textArea").value += "\r\n"+writeCurrentDate()+val+"所有版本号："+result.version;
                    } else {
                        layer.msg('获取当前版本失败！' + result.msg, {icon: 2, time: 1000});
                        document.getElementById("textArea").value = "\r\n"+writeCurrentDate()+result.msg;
                    }
                },
                error: function (result, type) {
                    layer.msg('获取当前版本失败2！', {icon: 2, time: 1000});
                    document.getElementById("textArea").value = "\r\n"+writeCurrentDate()+result;
                }
            });
        });

        // 保存sop信息
        form.on('submit(sopFormSubmit)', function(data) {
            console.log(document.getElementById('sop_file_url').value);
            if(!data.field.sopPath){
                layer.alert("请先选择SOP上传的文件！！", {
                    icon: 1,
                    time: 3000,
                    title: '错误'
                });
                return false;
            }

            $.ajax({
                type: 'POST',
                url: "./index/upload_sop_save",
                data: data.field,
                async: true,
                success: function(result) {
                    console.log(result);
                    if (result.code == 0) {
                        layer.msg('保存成功', {icon: 1, time: 3000});
                        document.getElementById('sop_file_url').value="";
                    } else {
                        layer.msg('保存失败！' + result.msg, {icon: 2, time: 3000});
                    }
                },
                error: function(result, type) {
                    layer.msg('保存失败！', {icon: 2, time: 3000});
                }
            });
        });

        //sop单个文件上传
        upload.render({
            elem: '#file_input_one'
            ,url: './index/upload_one'
            ,auto: true
            ,multiple: true
            ,drag: true
            ,accept: 'file' //普通文件
            //,exts: 'zip|rar|7z' //只允许上传压缩文件
            ,bindAction: '#uploadBtn'
            ,progress: function(e , percent) {
                console.log("进度：" + percent + '%');
                element.progress('progressBar',percent  + '%');
            }
            ,before: function(obj) {
                layer.msg('文件上传中...', {
                    icon: 16,
                    shade: 0.01,
                    time: 0
                })
            }
            ,done: function(res){
                console.log(res);
                layer.close(layer.msg());
                if(res.code == "fail"){
                    layer.msg("上传失败！！！");
                }
                if(res.code == "success"){
                    layer.msg("上传完成");
                    // 调用上传表单
                    document.getElementById("sop_file_url").value = res.url;
                    document.getElementById("textArea").value += "\r\n"+writeCurrentDate()+"Upload-->"+res.url;
                }
            }
        });

        //dep单个文件上传
        upload.render({
            elem: '#dep_file_input_one'
            ,url: './index/upload_one'
            ,auto: true
            ,multiple: true
            ,drag: true
            ,accept: 'file' //普通文件
            //,exts: 'zip|rar|7z' //只允许上传压缩文件
            ,bindAction: '#uploadBtn'
            ,progress: function(e , percent) {
                console.log("进度：" + percent + '%');
                element.progress('progressBar',percent  + '%');
            }
            ,before: function(obj) {
                layer.msg('文件上传中...', {
                    icon: 16,
                    shade: 0.01,
                    time: 0
                })
            }
            ,done: function(res){
                console.log(res);
                layer.close(layer.msg());
                if(res.code == "fail"){
                    layer.msg("上传失败！！！");
                }
                if(res.code == "success"){
                    layer.msg("上传完成");
                    // 调用上传表单
                    document.getElementById("dep_file_url").value = res.url;
                    document.getElementById("textArea").value += "\r\n"+writeCurrentDate()+"Upload-->"+res.url;
                }
            }
        });

        //保存dep信息
        form.on('submit(depFormSubmit)', function(data) {
            console.log(document.getElementById('dep_file_url').value);
            if(!data.field.depPath){
                layer.alert("请先选择依赖包上传的文件！！", {
                    icon: 1,
                    time: 3000,
                    title: '错误'
                });
                return false;
            }

            $.ajax({
                type: 'POST',
                url: "./index/upload_dep_save",
                data: data.field,
                async: true,
                success: function(result) {
                    console.log(result);
                    if (result.code == 0) {
                        layer.msg('保存成功', {icon: 1, time: 3000});
                        document.getElementById('dep_file_url').value="";
                    } else {
                        layer.msg('保存失败！' + result.msg, {icon: 2, time: 3000});
                    }
                },
                error: function(result, type) {
                    layer.msg('保存失败！', {icon: 2, time: 3000});
                }
            });
        });

    })

    function writeCurrentDate() {
        var now = new Date();
        var year = now.getFullYear(); //得到年份
        var month = now.getMonth();//得到月份
        var date = now.getDate();//得到日期
        var day = now.getDay();//得到周几
        var hour = now.getHours();//得到小时
        var minu = now.getMinutes();//得到分钟
        var sec = now.getSeconds();//得到秒
        var MS = now.getMilliseconds();//获取毫秒
        var week;
        month = month + 1;
        if (month < 10) month = "0" + month;
        if (date < 10) date = "0" + date;
        if (hour < 10) hour = "0" + hour;
        if (minu < 10) minu = "0" + minu;
        if (sec < 10) sec = "0" + sec;
        if (MS < 100) MS = "0" + MS;
        var arr_week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
        week = arr_week[day];
        var time = "";
        time = year + "/" + month + "/" + date + "/" + " " + hour + ":" + minu + ":" + sec +" ";
        //当前日期赋值给当前日期输入框中（jQuery easyUI）
        //$("#currentDate").html(time);
        //设置得到当前日期的函数的执行间隔时间，每1000毫秒刷新一次。
        var timer = setTimeout("writeCurrentDate()", 1000);
        return time;
    }

</script>
</body>
</html>